//-------------------------------------------------------------------------------------------------
// <copyright file="NativeMethods.cs" company="Anthony Adam">
// Copyright (c) Anthony Adam 2012. All rights reserved.
// </copyright>
//-------------------------------------------------------------------------------------------------
// ReSharper disable once CheckNamespace
namespace SuperStarRounds
{
  using System;
  using System.Runtime.InteropServices;

  /// <summary>
  /// Utility class providing access to windows system calls.
  /// </summary>
  internal class NativeMethods
  {
    /// <summary>
    /// Windows internal constant
    /// </summary>
    internal const int WmUser = 0x0400;
    
    /// <summary>
    /// Windows internal constant
    /// </summary>
    internal const int EmFormatrange = WmUser + 57;
    
    /// <summary>
    /// Windows internal constant
    /// </summary>
    internal const int EmLineindex = 0x00BB;
    
    /// <summary>
    /// Windows internal constant
    /// </summary>
    internal const int EmLinelength = 0x00C1;
    
    /// <summary>
    /// Windows internal constant
    /// </summary>
    internal const int EmPosfromchar = 0x00D6;
    
    /// <summary>
    /// Windows internal constant
    /// </summary>
    internal const int EmCharfrompos = 0x00D7;
    
    /// <summary>
    /// Windows internal constant
    /// </summary>
    internal const int EmGetfirstvisibleline = 0xCE;
    
    /// <summary>
    /// Prevents a default instance of the <see cref="NativeMethods"/> class from being created.
    /// </summary>
    private NativeMethods()
    {
    }

    [DllImport("user32")]
    internal static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wp, ref FormatRange lp);

    [DllImport("user32", CharSet = CharSet.Auto, EntryPoint = "SendMessage")]
    internal static extern IntPtr SendMessageInt(
      IntPtr handle,
      uint msg,
      IntPtr wParam,
      IntPtr lParam);
    
    [DllImport("user32", EntryPoint = "ShowCaret")]
    [return: MarshalAs(UnmanagedType.Bool)]
    internal static extern bool ShowCaretAPI(
      IntPtr hwnd);
    
    /// <summary>
    /// Internal structure for windows system calls needing a rectangle.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    internal struct Rect
    {
      /// <summary>
      /// Left extremity
      /// </summary>
      public int Left;
      
      /// <summary>
      /// Top extremity
      /// </summary>
      public int Top;
      
      /// <summary>
      /// Right extremity
      /// </summary>
      public int Right;
      
      /// <summary>
      /// Bottom extremity
      /// </summary>
      public int Bottom;
    }

    /// <summary>
    /// Internal structure for windows system calls needing a character range.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    internal struct CharRange
    {
      /// <summary>
      /// First character of range (0 for start of doc)
      /// </summary>
      public int cpMin; 
      
      /// <summary>
      /// Last character of range (-1 for end of doc)
      /// </summary>
      public int cpMax; 
    }

    /// <summary>
    /// Internal structure for windows system calls needing a device context definition.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    internal struct FormatRange
    {
      /// <summary>
      /// Actual DC to draw on
      /// </summary>
      public IntPtr hdc; 
      
      /// <summary>
      /// Target DC for determining text formatting
      /// </summary>
      public IntPtr hdcTarget; 
      
      /// <summary>
      /// Region of the DC to draw to (in twips)
      /// </summary>
      public Rect rc; 
      
      /// <summary>
      /// Region of the whole DC (page size) (in twips)
      /// </summary>
      public Rect rcPage; 
      
      /// <summary>
      /// Range of text to draw (see earlier declaration)
      /// </summary>
      public CharRange chrg; 
    }
  }
}